home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / database / postgres / appgen-0.2-a / appgen-0 / AppGEN / src / lib / datetime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-11  |  2.4 KB  |  104 lines

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <time.h>
  4. #include <string.h>
  5.  
  6. char *getword(int, char*, char*);
  7. char *caps(char[]);
  8.  
  9.  
  10. void ag_sysdate(char date[])
  11. {
  12.     time_t t;
  13.     char now[4096];
  14.     char word[256];
  15.     char day[256];
  16.     t=time(NULL);
  17.     strcpy(now,ctime(&t));    
  18. /*    strcpy(date,"\'"); */
  19.     strcpy(day,getword(3,now,word));
  20.     if (strlen(day)<2) strcat(date,"0");
  21.     strcat(date,day);
  22.     strcat(date,"-");
  23.     if (strcmp(caps(getword(2,now,word)),"JAN")==0) strcat(date,"01");
  24.     if (strcmp(caps(getword(2,now,word)),"FEB")==0) strcat(date,"02");
  25.     if (strcmp(caps(getword(2,now,word)),"MAR")==0) strcat(date,"03");
  26.     if (strcmp(caps(getword(2,now,word)),"APR")==0) strcat(date,"04");
  27.     if (strcmp(caps(getword(2,now,word)),"MAY")==0) strcat(date,"05");
  28.     if (strcmp(caps(getword(2,now,word)),"JUN")==0) strcat(date,"06");
  29.     if (strcmp(caps(getword(2,now,word)),"JUL")==0) strcat(date,"07");
  30.     if (strcmp(caps(getword(2,now,word)),"AUG")==0) strcat(date,"08");
  31.     if (strcmp(caps(getword(2,now,word)),"SEP")==0) strcat(date,"09");
  32.     if (strcmp(caps(getword(2,now,word)),"OCT")==0) strcat(date,"10");
  33.     if (strcmp(caps(getword(2,now,word)),"NOV")==0) strcat(date,"11");
  34.     if (strcmp(caps(getword(2,now,word)),"DEC")==0) strcat(date,"12");
  35.     strcat(date,"-");
  36.     strcat(date,getword(5,now,word));
  37.     date[strlen(date)-1]=0;
  38. /*    strcat(date,"\'"); */
  39.  
  40. }
  41.  
  42. void ag_systime(char timev[])
  43. {
  44.     time_t t;
  45.     char now[4096];
  46.     char word[256];
  47.     t=time(NULL);
  48.     strcpy(now,ctime(&t));    
  49. /*    strcpy(timev,"\'"); */
  50.     strcpy(timev,getword(4,now,word));
  51. /*    strcat(timev,"\'"); */
  52.  
  53. }
  54.  
  55.  
  56. char *getword(int word_number, char *line, char *word)
  57. {
  58.     int a,b,c,in_quotes=0;
  59.     b=0;
  60.     for (a=0; a<256; a++) word[a]=0;
  61.     a=0;
  62.     c=0;
  63.     while(a<strlen(line)) {
  64.         if (!in_quotes) if ((line[a]==' ') || (line[a]=='\t')) {
  65.             while (((line[a]==' ')||(line[a]=='\t'))&&(a<strlen(line))) a++;
  66.             word[b]=0;
  67.             b=0;
  68.             c++;
  69.             if (c==word_number) return(word);
  70.             }
  71.         if (in_quotes) if (line[a]=='\"') {
  72.             a++;
  73.             while (((line[a]==' ')||(line[a]=='\t'))&&(a<strlen(line))) a++;
  74.             word[b]='\"';
  75.             b++;
  76.             word[b]=0;
  77.             b=0;
  78.             c++;
  79.             in_quotes=0;
  80.             if (c==word_number) return(word);
  81.             }
  82.         if (line[a]=='\"') {
  83.             if (in_quotes==1) in_quotes=0;
  84.             else in_quotes=1;
  85.             }
  86.         word[b]=line[a];
  87.         b++;
  88.         a++;
  89.         }
  90.     word[b]=0;
  91.     return(word);
  92. }
  93.  
  94.  
  95. char *caps(char* var1)
  96. {
  97.     int a;
  98.     char var[256];
  99.     strcpy(var, var1);
  100.     for (a=0; a<strlen(var); a++) if (var[a]>=97) var[a]-=97-65;
  101.     return(var);
  102. }
  103.         
  104.